// ������ת��������

package Leetcode;

class solution_033 {
	public int search(int[] nums, int target) {
		int length = nums.length;
		if (length == 0)
			return -1;
		if (length == 1)
			if (nums[0] == target)
				return 0;
			else
				return -1;
		int k = 0;
		for (int i = 0; i < nums.length; i++)
			if (nums[i] < nums[i + 1]) {
				k = i + 1;
				break;
			}
		int left = k, right = k - 1 + length;
		while (true) {
			if ((left - k + 0.5) * (right - k + 0.5) > 0 && left > right)
				break;
			int mid = 0;
			if ((left - k + 0.5) * (right - k + 0.5) < 0)
				mid = (int) (((left + right + length) / 2) % length);
			else
				mid = (int) ((left + right) / 2);
			if (nums[mid] == target)
				return mid;
			else if (nums[mid] < target)
				left = (mid + 1) % length;
			else
				right = (mid - 1) % length;
		}
		return -1;
	}
}

// �������볬��ʱ������
public class Solution033 {
	public int search(int[] nums, int target) {
		int length = nums.length;
		if (length == 0)
			return -1;
		if (length == 1)
			return nums[0] == target ? 0 : -1;
		int left = 0, right = length - 1;
		while (left <= right) {
			int mid = (left + right) / 2;
			if (nums[mid] == target)
				return mid;
			if (nums[left] <= nums[mid]) {
				if (nums[left] <= target && target < nums[mid])
					right = mid - 1;
				else
					left = mid + 1;
			} else {
				if (nums[mid] < target && target <= nums[right])
					left = mid + 1;
				else
					right = mid - 1;
			}
		}
		return -1;
	}

	public static void main(String[] args) {
		System.out.println(-1 % 7);
	}
}
